import os
import logging.config
from src.basedata.infrastructure.utils.context import context_request_id

if not os.path.isdir('log'):
    os.mkdir('log')

path = os.path.abspath(os.path.join(os.getcwd(), "."))
logdir = path + '/etc/log.conf'
logging.config.fileConfig(path + '/etc/log.conf')


class MyFilter(logging.Filter):
    def filter(self, record):
        request_id = ""
        try:
            request_id = context_request_id.get("-")
        except Exception as e:
            pass
        record.request_id = request_id
        return True


my_filter = MyFilter()
for handler in logging.getLogger().handlers:
    handler.addFilter(my_filter)
